package com.twu.biblioteca.service;

import com.twu.biblioteca.Library;
import com.twu.biblioteca.model.Account;
import com.twu.biblioteca.model.LoginStatus;

import java.util.ArrayList;
import java.util.List;

import static com.twu.biblioteca.model.LoginStatus.login;

public class UserService {
    private Library library;

    public void setLibrary(Library library) {
        this.library = library;
    }


    public boolean userLogin(String userId, String password) {
        boolean result = false;
        Account account = library.findUser(userId);
        if (account != null && account.getPassword().equals(password)) {
            library.markUserLogin(account);
            result = true;
        }
        return result;
    }


    public Account getUserById(String accountId) {
        return library.findUser(accountId);
    }

    public boolean checkLogin(String accountId) {
      Account account=library.findUser(accountId);
        if(account!=null&& login.equals(account.getStatus())){
            return true;
        }else {
            return false;
        }

    }
}
